package rpg.role
{
	import rpg.Utils.Val;
	import rpg.avatar.AvatarComponent;
	import rpg.core.AutoCastSpellComponent;
	import rpg.core.GameComponent;
	import rpg.data.GameData;
	import rpg.data.SpriteStat;
	import rpg.state.StateComponent;

	public class StateObject extends SceneObject
	{
		public var avatarComponent : AvatarComponent;
		public var stateComponent : StateComponent;
		public var autoCastSpellComponent : AutoCastSpellComponent;

		/**
		 * 是否无敌
		 */
		public var isInvicible : Boolean = false;

		/**
		 * 是否BUFFER 引起的能否攻击
		 */
		public var fightable : Boolean = true;

		/**
		 * BUFFER 引起的能否移动
		 */
		public var movable : Boolean = true;
		/**
		 * 物理无敌
		 */
		public var invincibility : Boolean = false;
		/**
		 * 是否魔法免疫
		 */
		public var magicImmunity : Boolean = false;
		/**
		 * 沉默
		 */
		public var isHush : Boolean = false;

		/**
		 * 冲锋
		 */
		public var isRush : Boolean = false;
		/**
		 * 是否处于硬直
		 */
		public var isHardTime : Boolean = false;

		public function StateObject(id : String)
		{
			super(id);
		}

		override public function addComponent(com : GameComponent , priority : int = 0) : void
		{
			super.addComponent(com , priority);
			if(com is AvatarComponent)
				avatarComponent = com as AvatarComponent;
			if(com is StateComponent)
				stateComponent = com as StateComponent;
			if(com is AutoCastSpellComponent)
				autoCastSpellComponent = com as AutoCastSpellComponent;
		}

		public function get canWalk() : Boolean
		{
			return movable && !isHardTime && !isDead && !isJump && !isBlink && !isRush && !isBeatBack && !isBeenAttack && !isStun;
		}

		public function get canAttack() : Boolean
		{
			return fightable && !isHardTime && !isHush && !isDead && !isCastSpell && !isAttack && !isJump && !isBlink && !isRush && !isBeatBack && !isBeenAttack && !isStun;
		}

		public function get isDead() : Boolean
		{
			return avatarComponent.state == Val.DEAD;
		}

		public function get isWalk() : Boolean
		{
			return avatarComponent.state == Val.WALK;
		}

		public function get isStand() : Boolean
		{
			return avatarComponent.state == Val.STAND;
		}

		public function get isCastSpell() : Boolean
		{
			return avatarComponent.state == Val.CASTSPELL;
		}

		public function get isAttack() : Boolean
		{
			return avatarComponent.state == Val.ATTACK;
		}

		public function get isJump() : Boolean
		{
			return avatarComponent.state == Val.JUMP;
		}

		public function get isSit() : Boolean
		{
			return avatarComponent.state == Val.SIT;
		}

		public function get isBlink() : Boolean
		{
			return avatarComponent.state == Val.BLINK;
		}

		public function get isBeatBack() : Boolean
		{
			return avatarComponent.state == Val.BEATBACK;
		}

		public function get isBeenAttack() : Boolean
		{
			return avatarComponent.state == Val.BEENATTACK;
		}

		public function get isStun() : Boolean
		{
			return avatarComponent.state == Val.STUN;
		}

		public function get state() : int
		{
			return avatarComponent.state;
		}

		public function set state(value : int) : void
		{
			avatarComponent.state = value;
		}

		public function changeState(value : int) : void
		{
			stateComponent.changeState(value);
		}

		public function get dir() : int
		{
			return avatarComponent.dir;
		}

		public function set dir(value : int) : void
		{
			avatarComponent.dir = value;
		}
	}
}